import React, {Component, PropTypes} from "react";
import {Link} from "react-router";
import OrderGoodsList from "./OrderGoodsList";
import cookie from 'react-cookie';


class OrderData extends Component {
    constructor(props) {
        super(props);
        console.log("orderId:" + this.props.item.orderId);
        this.state = {
            orderId: this.props.item.orderId,
        }
    }

    goToPay(){
        window.location.href = "http://weixin.hzyisu.com/orderPay.html?orderId=" + this.props.item.orderId;
    }

    orderListThree() {
        if (this.props.item.orderStatus == 0) {
            return (
                <div className="mall-myOrder-three">
                    <p>
                        <span>实付：￥{this.props.item.orderAmount}</span>
                        <Link onClick={this.cancelOrder.bind(this)}>取消订单</Link>
                        <Link onClick={this.goToPay.bind(this)}>付款</Link>
                    </p>
                </div>
            )
        } else if (this.props.item.orderStatus == -100) {
            return (
                <div>
                    <p className="total-p">合计：￥{this.props.item.orderAmount}</p>
                </div>
            )
        } else if (this.props.item.orderStatus == 10) {
            return (
                <div className="mall-myOrder-other">
                    <p>
                        <span>实付：{this.props.item.orderAmount}</span>
                        {/*<Link onClick={this.cancelOrder.bind(this)}>取消订单</Link>*/}
                    </p>
                </div>
            )
        } else if (this.props.item.orderStatus == 20) {
            return (
                <div className="mall-myOrder-other">
                    <p>
                        <span>实付：{this.props.item.orderAmount}</span>
                        <Link onClick={this.confirmReceipt.bind(this)}>确认收货</Link>
                    </p>
                </div>
            )
        } else if (this.props.item.orderStatus == 100) {
            return (
                <div className="mall-myOrder-three">
                    <p>
                        <span>实付：{this.props.item.orderAmount}</span>
                        {/*<Link to={''}>查看物流</Link>*/}
                        {/*<Link to={''}>评论</Link>*/}
                    </p>
                </div>
            )
        } else if (this.props.item.orderStatus == -10) {
            return (
                <div className="mall-myOrder-three">
                    {/*<p>*/}
                    {/*<span>实付：{this.props.item.orderAmount}</span>*/}
                    {/*<Link to={''}>查看物流</Link>*/}
                    {/*<Link to={''}>查看退款</Link>*/}
                    {/*</p>*/}
                </div>
            )
        }
    }

    cancelOrder() {
        if (confirm("是否取消订单")) {
            this.props.cancelOrder(this.state.orderId);
        }
    }

    confirmReceipt() {
        if (confirm("是否确认收货")) {
            this.props.confirmReceipt(this.state.orderId);
        }
    }

    render() {
        const {item} = this.props;
        return (
            <div>
                <ul className="commodity-list">
                    <li>
                        <div className="mall-myOrder-one">
                            <span>订单编号：{item.orderId}</span>
                            <p>{item.orderStatusDesc}</p>
                        </div>
                    </li>
                    {
                        item.orderSubVos.map((goodsItem, index) => {
                            return (
                                <OrderGoodsList item={goodsItem} key={index}/>
                            )
                        })
                    }
                    <li>
                        {this.orderListThree()}
                    </li>
                </ul>
            </div>
        )
    }

}
export default OrderData